package com.fram.controller.admin;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.sys.PageBean;
import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.apiversion.ApiVersion;
import com.fram.common.util.base.BaseAdminController;
import com.fram.entity.RecoveryForm;
import com.fram.service.admin.RecoveryService;

@RestController
@RequestMapping("/admin/{version}/auth/recovery")
public class RecoveryController extends BaseAdminController{
	
	private static Logger LOG = LoggerFactory.getLogger(RecoveryController.class);
	
	@Autowired
	private RecoveryService recoveryService;
	
	@ApiVersion(1.0)
	@RequestMapping("list")
	private ResponseMsg list(@RequestBody PageBean<RecoveryForm> request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			if(getDistributorId()!=null) {
			request.getParam().setDistributorId(getDistributorId());
			}
			msg.setData(recoveryService.list(request));
		} catch (ProException e) {
			LOG.error("-后台-待回收列表出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台-待回收列表异常-->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
	
	/**确认回收 确认收到货**/
	@ApiVersion(1.0)
	@RequestMapping("update")
	private ResponseMsg update(@RequestBody RecoveryForm request) {
		ResponseMsg msg =ResponseMsg.returnBeanBuild();
		try {
			recoveryService.update(request);
		} catch (ProException e) {
			LOG.error("-后台-修改为确定回收->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-后台-修改为确定回收-->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
